package com.example.score.controller;


import com.example.score.dto.AjaxResult;
import com.example.score.entity.input.SchoolBaseInput;
import com.example.score.entity.vo.*;
import com.example.score.service.SchoolBasedCountService;
import com.example.score.utils.SchoolBasedExcelUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/school/based")
public class SchoolBasedCountController {

    @Resource
    private SchoolBasedCountService schoolBasedCountService;


    /**
     * 作业次数
     *
     * @param param
     * @return
     */
    @GetMapping("/examCount")
    public AjaxResult examCount(SchoolBaseInput param) {
        ExamCountVo examCountVo = schoolBasedCountService.examCount(param);
        return AjaxResult.success(examCountVo);
    }

    /**
     * 作业扫描总量
     *
     * @param param
     * @return
     */
    @GetMapping("/examScanCount")
    public AjaxResult examScanCount(SchoolBaseInput param) {
        ExamCountVo examCountVo = schoolBasedCountService.examScanCount(param);
        return AjaxResult.success(examCountVo);
    }

    /**
     * 作业分布
     *
     * @param param
     * @return
     */
    @GetMapping("/examDistribute")
    public AjaxResult examDistribute(SchoolBaseInput param) {
        ExamDistributeVo examDistributeVo = schoolBasedCountService.examDistribute(param);
        return AjaxResult.success(examDistributeVo);
    }



    /**
     * 学科排名
     *
     * @param param
     * @return
     */
    @GetMapping("/subjectRank")
    public AjaxResult subjectRank(SchoolBaseInput param) {
        List<StudentSubmitSubjectVo> subjectRank = schoolBasedCountService.subjectRank(param);
        return AjaxResult.success(subjectRank);
    }


    /**
     * 学习情况列表
     *
     * @param param
     * @return
     */
    @GetMapping("/listExamInfo")
    public AjaxResult listExamInfo(SchoolBaseInput param) {
        List<ExamInfoVo> list = schoolBasedCountService.listExamInfo(param);
        return AjaxResult.success(list);
    }


    /**
     * 导出学习情况
     *
     * @param param 参数
     */
    @GetMapping("/examInfo/export")
    public void exportTopList(SchoolBaseInput param, HttpServletResponse response) throws IOException {
        List<ExamInfoVo> data = schoolBasedCountService.listExamInfo(param);
        //转为excel实体
        List<ExamInfoExcelVo> list = schoolBasedCountService.dataToExcel(data);
        SchoolBasedExcelUtils.exportExcel(response, list);
    }


    @GetMapping("/listYears/{schoolId}")
    public AjaxResult listYears(@PathVariable("schoolId") Long schoolId) {
        List<Integer> years = schoolBasedCountService.listYears(schoolId);
        return AjaxResult.success(years);
    }
}
